Page({
  data: {
    userInfo: {
      avatar: '',
      nickName: '',
    },
  },
  onLoad() {
    // console.log('onLoad----')
  },
  onShow() {
    // console.log('onShow----')
    this.getUserInfo()
  },

  async getUserInfo() {
    const { code, data: userInfo } = await wx.http.get('/userInfo')
    if (code !== 10000) return wx.utils.toast('获取用户信息失败')
    this.setData({
      userInfo,
    })
    // 存储用户信息到本地
    wx.setStorageSync('userInfo', userInfo)
  },

  goLogin() {
    wx.navigateTo({
      url: '/pages/login/index',
    })
  },
})
